package weixin02.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import weixin02.entity.Goods;
import weixin02.query.LimitQuery;
import weixin02.service.GoodsService;
import org.springframework.web.bind.annotation.*;
import weixin02.util.R;

import javax.annotation.Resource;

/**
 * (Goods)表控制层
 * @author makejava
 * @since 2021-07-06 21:14:22
 */
@Api(tags = "商品信息接口")
@RestController
@RequestMapping("goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    /*根据'id'查询商品信息*/
    @ApiOperation(value = "根据'id'查询商品信息",notes = "根据'id'查询商品信息")
    @GetMapping("queryGoodById")
    public R queryGoodById(Integer id) {
        return goodsService.queryById(id);
    }

    /*根据'类型'查询商品信息*/
    @ApiOperation(value = "根据'类型'查询商品信息",notes = "根据'类型'查询商品信息[type_id:1,2,3,4,5,6]")
    @GetMapping("queryGoodsByType")
    public R queryGoodsByType(int goodsType){
        return goodsService.queryGoodsByType(goodsType);
    }

    /*根据名称查询商品*/
    @ApiOperation(value = "根据名称查询商品信息",notes = "根据名称查询商品信息")
    @GetMapping("queryGoodsByName")
    public R queryGoodsByName(String goodsName){
        return goodsService.queryGoodsByName(goodsName);
    }

    /*查询所有商品信息*/
    @ApiOperation(value = "查询所有商品信息",notes = "查询所有商品信息")
    @GetMapping("queryAllGoods")
    public R queryAllGoods(){
        return goodsService.queryAll();
    }

    /*分页查询所有商品信息*/
    @ApiOperation(value = "分页查询所有商品信息",notes = "分页查询所有商品信息")
    @GetMapping("queryAllGoodsByLimit")
    public R queryAllGoodsByLimit(LimitQuery query){
        return goodsService.queryAllByLimit(query);
    }

    /*增加商品*/
    @ApiOperation(value = "增加商品",notes = "增加商品")
    @GetMapping("addGoods")
    public R addGoods(Goods goods){
        return goodsService.insert(goods);
    }

    /*删除商品*/
    @ApiOperation(value = "删除商品",notes = "根据id删除商品")
    @GetMapping("deleteGoods")
    public R deleteGoods(int id){
        return goodsService.deleteById(id);
    }

    /*更新商品*/
    @ApiOperation(value = "更新商品",notes = "根据id删除商品")
    @GetMapping("updateGoods")
    public R updateGoods(Goods goods){
        return goodsService.update(goods);
    }

}
